// 渲染用户信息
function renderAuthor(currentUser) {
    document.querySelector('.author_avatar').src = currentUser.avatar
    document.querySelector('.author-username').textContent = currentUser.username
    document.querySelector('.author-git').herf = currentUser.gitRepo
}

function renderCount(articleCount, typeCount) {
    document.querySelector('.article-count').textContent = articleCount
    document.querySelector('.type-count').textContent = typeCount
}

// 渲染文章内容
function renderContent(article) {
    var container = document.querySelector('.content')
    var html = `<div class="blog">` +
        `<div class="title">${article.title}</div>` +
        `<div class="date">${article.publishedAt}</div>` +
        `<div class="desc">${article.content}</div>` +
        `</div>`;
    container.innerHTML += html
}

var aid
var xhr = new XMLHttpRequest();
// xhr.open("GET", '/json/blog_content.json')
xhr.open("GET", '/blog_content.json' + location.search + "&time=" + Date.now())
xhr.onload = function () {
    alert(xhr.responseText)
    var data = JSON.parse(xhr.responseText)
    if (!data.currentUser) {
        location.assign('/login.html')
        return
    }
    renderAuthor(data.currentUser)
    renderCount(data.articleCount, data.typeCount)
    renderContent(data.article)
}
xhr.send()